package com.accp.crm.service;

import java.util.List;

import org.hibernate.SessionFactory;

import com.accp.crm.dao.CommonDAO;
import com.accp.crm.entity.CstCustomer;
import com.accp.crm.entity.CstLinkman;

public class CstLinkmanService implements ICstLinkman {
	
	private CommonDAO<CstLinkman> linkman;
	
	public void setSessionFactory(SessionFactory sessionFactory){
		linkman = new CommonDAO<CstLinkman>(sessionFactory,CstLinkman.class);
	}

	@Override
	public void addLinkman(CstLinkman cstLinkman) {
		this.linkman.save(cstLinkman);

	}

	@Override
	public CstLinkman findByLinkman(Long id) {
		String hql = "from CstLinkman c where c.lkmId=?";
		List list = this.linkman.findByHQL(hql, id);
		return (CstLinkman) list.get(0);
	}

	@Override
	public void delete(Long id) {
		CstLinkman linkman = this.linkman.findById(id);
		this.linkman.delete(linkman);
		
	}

	@Override
	public void update(CstLinkman cstLinkman) {
		this.linkman.update(cstLinkman);
		
	}

	@Override
	public CstLinkman findById(Long id) {
		return this.linkman.findById(id);
	}

	@Override
	public List findAll(String custNo) {
		String hql = "from CstLinkman c where c.cstCustomer=?";
		return this.linkman.findByHQL(hql, custNo);
	}


}
